import React,{Component} from 'react';

import '../../styles/App.less';
//首页里获取数据
import axios from 'axios';
import Swiper from '../../components/main/swiper';
import NowPlayingList from '../../components/main/nowPlayingList';
import CommingSoonList from '../../components/main/commingSoonList';
class Main extends Component{
	//数据初始化
	constructor(){
		super();
		this.state = {
			swiperList:[],//保存轮播图
			nowPlayingList:[],//正在上映的数据
			commingSoonList:[]//即将上映的数据
		}
		
		
	}
	//在钩子函数中获取数据
	componentDidMount(){
		axios.get("/v4/api/billboard/home?__t=1536918673951").then(res=>{
//			console.log(res);
			//将数据写到 state中
			this.setState({
				swiperList:res.data.data.billboards
			})
		})
		axios.get('/v4/api/film/now-playing?__t=1537181821853&page=1&count=5')
		.then(resp=>{
//			console.log(resp);
			//将数据写到 state中
			this.setState({
				nowPlayingList:resp.data.data.films
			})
		})
		axios.get('/v4/api/film/coming-soon?__t=1537709449103&page=1&count=5')
		.then(rep=>{
//			console.log(rep);
			//将数据写到 state中
			this.setState({
				commingSoonList:rep.data.data.films
			})
			console.log(this.state.commingSoonList)
		})
	}
	
	render(){
		return (
			<div>
				<div>
					<Swiper swiperList={this.state.swiperList}/>
					<NowPlayingList nowPlayingList={this.state.nowPlayingList} />
					<CommingSoonList commingSoonList={this.state.commingSoonList} />
				</div>
			</div>
		)
		
	}
}


//输出
export default Main;